//------------------------------------------------------------------------------
// Fichiers d'ent�te utilis�s
//------------------------------------------------------------------------------
#include "RGBImage.hpp"
#include "GrayImage.hpp"
#include <GL/gl.h>

//------------------------------------------------------------------------------
// Définition de constantes
//------------------------------------------------------------------------------

namespace ImageAnalysis
{
	//----------------------------------------------------------------------
	// Constructeur
	//----------------------------------------------------------------------
	unsigned char RGBImage::Red[] 	= { 255, 0, 0 };
	unsigned char RGBImage::Green[] 	= { 0, 255, 0 };
	unsigned char RGBImage::Blue[] 	= { 0, 0, 255 };
	unsigned char RGBImage::Orange[] 	= { 255, 255, 0 };
	unsigned char RGBImage::Yellow[] 	= { 0, 255, 255 };

	//----------------------------------------------------------------------
	// Constructeur
	//----------------------------------------------------------------------
	RGBImage::RGBImage( int width, int height ):
	Image(width, height)
	{
		//allocation de la structure contenant les pixels
		pixels = new unsigned char [width*height*4];
	}

	//----------------------------------------------------------------------
	// Destructeur
	//----------------------------------------------------------------------
	RGBImage::~RGBImage( )
	{
		delete pixels;
	}

    //----------------------------------------------------------------------
    //
    //----------------------------------------------------------------------
    void RGBImage::Draw()
    {
        glDrawPixels( layerWidth, layerHeight, GL_RGBA, GL_UNSIGNED_BYTE, pixels );
    }

    //----------------------------------------------------------------------
    //
    //----------------------------------------------------------------------
	unsigned char* RGBImage::GetPixel( int index )
	{
		return &pixels[index+((index)*3)];
	}

    //----------------------------------------------------------------------
    //
    //----------------------------------------------------------------------
	void RGBImage::SetPixel( int index, unsigned char* value )
	{
		pixels[index+(index*3)]	 =value[2];
		pixels[index+(index*3)+1]=value[1];
		pixels[index+(index*3)+2]=value[0];
		pixels[index+(index*3)+3]=255;//value[3];
	}
}

